import { createRenderer } from '@vue/runtime-core'
import { Container, Sprite, Texture } from 'pixi.js'

const { createApp } = createRenderer({
    createElement(type){
        let element;
        switch (type) {
            case "Container":
                element = new Container()
                break;
            case "Sprite":
                element = new Sprite()
                break;
            default:
                break;
        }
        return element
    },
    patchProp(el,key,oldValue,newValue){
        switch (key) {
            case 'texture':
                el.texture = Texture.from(newValue)
                break;
            case 'onClick':
                el.on('pointertap', newValue)
            default:
                el[key] = newValue
                break;
        }
    },
    createComment(){ },
    parentNode(){},
    nextSibling(){},
    remove(el){
        const parent = el.parent
        if(parent){
            parent.removeChild(el)
        }
    },
    insert(el,parent){//dom添加到canvas
        parent.addChild(el)
    }
})
export default createApp